<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #myCanvas{
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <center>
        <canvas id="myCanvas" width="400" height="400">

        </canvas>
    </center>
    
</body>
<script>
    /** @type {HTMLCanvasElement} */
    let myCanvas=document.querySelector("#myCanvas");
    let ctx=myCanvas.getContext("2d");
    
    //ctx.strokeRect(100,100,150,150);
    //将路径规划和执行封装成一个方法
    ctx.fillStyle="pink";
    ctx.fillRect(100,100,150,150);
    //将路径规划,执行绘图,填充封装在一起
    ctx.clearRect(200,200,30,30);
    //将路径规划,执行绘图,填充反色封装在一起
</script>
</html>